home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu738.dms / pu738.adf / aguide / aguide.c < prev    next >
C/C++ Source or Header  |  1994-06-01  |  6KB  |  281 lines

  1. ; /*
  2. dcc aguide.c dlib:start.o -lagstub -r -o AGuide
  3. quit ; */
  4. /*
  5. **    AGuide.c - an alternative to the original C= AmigaGuide frontend
  6. **    Written & (c) 1994 by AEsoftwares. Freeware.
  7. **
  8. **    Compile info: compile with DICE V2.##.## as
  9. **        dcc start.c aguide.c -lagstub -r -o AGuide
  10. **    Create - if necessary - agstubs.lib with
  11. **        fdtolib amigaguide_lib.fd -o agstubs.lib
  12. **
  13. **    Revision history:
  14. **
  15. **    V1.0 [16/05/94]  Initial release
  16. */
  17.  
  18. #include <string.h>
  19. #include <pd/start.h>
  20. #include <exec/types.h>
  21. #include <exec/libraries.h>
  22. #include <exec/execbase.h>
  23. #include <dos/dos.h>
  24. #include <dos/rdargs.h>
  25. #include <graphics/displayinfo.h>
  26. #include <intuition/intuition.h>
  27. #include <intuition/screens.h>
  28. #include <libraries/amigaguide.h>
  29. #include <libraries/asl.h>
  30. #include <utility/tagitem.h>
  31. #include <workbench/startup.h>
  32. #include <workbench/workbench.h>
  33. #include <clib/exec_protos.h>
  34. #include <clib/dos_protos.h>
  35. #include <clib/graphics_protos.h>
  36. #include <clib/intuition_protos.h>
  37. #include <clib/icon_protos.h>
  38. #include <clib/amigaguide_protos.h>
  39. #include <clib/asl_protos.h>
  40.  
  41. #define PROGNAME "AGuide"
  42. #define VERSION  "1.0"
  43. #define REVDATE  "16.5.94"
  44.  
  45. #define MAXNAMELEN 512
  46.  
  47. const char versiontag[] = "$VER: " PROGNAME " " VERSION " (" REVDATE ")";
  48.  
  49. struct args {
  50.     UBYTE *file;
  51.     UBYTE *pubscr;
  52.     UBYTE *ownscr;
  53.     UBYTE *port;
  54.     void (*error)(UBYTE *);
  55. };
  56.  
  57. struct Library *AmigaGuideBase;
  58.  
  59. BOOL fileexists(UBYTE *name) {
  60.     BPTR dummylock;
  61.  
  62.     if (dummylock = Lock(name, ACCESS_READ)) {
  63.         UnLock(dummylock);
  64.         return 1;
  65.     } else {
  66.         return 0;
  67.     }
  68. }
  69.  
  70. LONG mymain(struct args *args) {
  71.     LONG res = 0;
  72.  
  73.     if (!args->file) {
  74.         struct FileRequester *aslreq;
  75.         static UBYTE name[MAXNAMELEN];
  76.  
  77.         if (aslreq = AllocAslRequestTags(ASL_FileRequest,
  78.                 ASL_Hail, (ULONG)PROGNAME " - Select file to view",    TAG_DONE)
  79.         ) {
  80.             if (AslRequestTags(aslreq, TAG_DONE)) {
  81.                 strncpy(name, aslreq->rf_Dir, MAXNAMELEN - 1);
  82.                 name[MAXNAMELEN - 1] = 0;
  83.                 if (AddPart(name, aslreq->rf_File, MAXNAMELEN - 1)) {
  84.                     args->file = name;
  85.                     if (!fileexists(args->file)) {
  86.                         args->file = 0;
  87.                     }
  88.                 }
  89.             }
  90.             FreeAslRequest(aslreq);
  91.         }
  92.     }
  93.  
  94.     if (args->file) {
  95.         if (AmigaGuideBase = OpenLibrary("amigaguide.library", 34)) {
  96.             UBYTE pubsig = -1;
  97.             struct Screen *scr;
  98.             struct NewAmigaGuide nag = {
  99.                 0, 0, 0, 0, 0, args->port, PROGNAME, 0, 0, 0, 0, 0, 0
  100.             };
  101.             AMIGAGUIDECONTEXT aghandle;
  102.  
  103.             if (args->ownscr) {
  104.                 ULONG modeID;
  105.                 UWORD dummypens[] = {~0};
  106.                 struct TagItem ostags[] = {
  107.                     SA_DisplayID, 0,
  108.                     SA_Type, 0,
  109.                     SA_Title, 0,
  110.                     SA_PubName, 0,
  111.                     SA_PubSig, 0,
  112.                     SA_Pens, (ULONG) dummypens,
  113.                     SA_Depth, 2,
  114.                     TAG_DONE
  115.                 };
  116.                 UBYTE *tail;
  117.  
  118.                 modeID = strtol(args->ownscr, &tail, 0);
  119.                 if (*tail) {
  120.                     ULONG lastID = INVALID_ID;
  121.                     BOOL finished = 0;
  122.                     struct NameInfo nameInfo;
  123.  
  124.                     do {
  125.                         if ((modeID = NextDisplayInfo(lastID)) == INVALID_ID) {
  126.                             finished = 1;
  127.                         } else {
  128.                             lastID = modeID;
  129.                             if (GetDisplayInfoData(0, (APTR)&nameInfo,
  130.                                     sizeof(nameInfo), DTAG_NAME, modeID)) {
  131.                                 finished = !stricmp(nameInfo.Name, args->ownscr);
  132.                             }
  133.                         }
  134.                     } while (!finished);
  135.                 }
  136.                 if (modeID == INVALID_ID) {
  137.                     struct Screen *wbscr;
  138.  
  139.                     if (wbscr = LockPubScreen(0)) {
  140.                         modeID = GetVPModeID(&(wbscr->ViewPort))    ;
  141.                         UnlockPubScreen(0, wbscr);
  142.                     } else {
  143.                         modeID = HIRES_KEY;
  144.                     }
  145.                 }
  146.                 ostags[0].ti_Data = modeID;
  147.                 if (args->pubscr) {
  148.                     ostags[1].ti_Data = PUBLICSCREEN;
  149.                     ostags[2].ti_Data = ostags[3].ti_Data = args->pubscr;
  150.                     pubsig = AllocSignal(-1);
  151.                     ostags[4].ti_Data =
  152.                             (pubsig != -1) ? pubsig : SIGBREAKB_CTRL_C;
  153.                 } else {
  154.                     ostags[1].ti_Data = CUSTOMSCREEN;
  155.                     ostags[2].ti_Data = (ULONG)
  156.                             PROGNAME " V" VERSION " by AEsoftwares";
  157.                     ostags[3].ti_Tag = ostags[4].ti_Tag = TAG_IGNORE;
  158.                 }
  159.                 if (scr = OpenScreenTagList(0, ostags)) {
  160.                     PubScreenStatus(scr, 0);
  161.                 } else {
  162.                     args->error("Cannot open screen");
  163.                     res = 10;
  164.                 }
  165.             } else {
  166.                 if (args->pubscr && (scr = LockPubScreen(args->pubscr))) {
  167.                     ScreenToFront(scr);
  168.                     UnlockPubScreen(0, scr);
  169.                 }
  170.                 scr = 0;
  171.             }
  172.             nag.nag_Screen = scr;
  173.             nag.nag_PubScreen = args->ownscr ? 0 : args->pubscr;
  174.             nag.nag_Name = args->file;
  175.             if (aghandle = OpenAmigaGuide(&nag, 0)) {
  176.                 CloseAmigaGuide(aghandle);
  177.             } else {
  178.                 args->error("Cannot invoke AmigaGuide");
  179.                 res = 10;
  180.             }
  181.             if (scr) {
  182.                 while (!CloseScreen(scr)) {
  183.                     Wait((pubsig != -1) ? 1<<pubsig : SIGBREAKF_CTRL_C);
  184.                 }
  185.             }
  186.             if (pubsig != -1) {
  187.                 FreeSignal(pubsig);
  188.             }
  189.         } else {
  190.             args->error("Cannot open amigaguide.library");
  191.             res = 10;
  192.         }
  193.     } else {
  194.         res = 10;
  195.     }
  196.     return res;
  197. }
  198.  
  199. void putstr(UBYTE *msg) {
  200.  
  201.     PutStr(msg);
  202.     PutStr("\n");
  203. }
  204.  
  205. LONG clistart(ULONG len, UBYTE *ptr) {
  206.     UBYTE *templ = "DATABASE,PS=PUBSCREEN/K,OS=OWNSCREEN/K,PN=PORTNAME/K";
  207.     LONG buf[] = {0, 0, 0, 0};
  208.     struct RDArgs *rda;
  209.     struct args args;
  210.     LONG res;
  211.     static UBYTE name[MAXNAMELEN];
  212.  
  213.     args.error  = &putstr;
  214.     if (rda = ReadArgs(templ, buf, 0)) {
  215.         args.file   = (UBYTE *) buf[0];
  216.         args.pubscr = (UBYTE *) buf[1];
  217.         args.ownscr = (UBYTE *) buf[2];
  218.         args.port   = (UBYTE *) buf[3];
  219.  
  220.         if (args.file) {
  221.             strncpy(name, args.file, MAXNAMELEN - 7);
  222.             name[MAXNAMELEN - 7] = 0;
  223.             strcat(name, ".guide");
  224.             if (fileexists(name)) {
  225.                 args.file = name;
  226.             } else if (!fileexists(args.file)) {
  227.                 args.file = 0;
  228.             }
  229.         }
  230.  
  231.         res = mymain(&args);
  232.         FreeArgs(rda);
  233.     } else {
  234.         args.error("Bad args");
  235.         res = 10;
  236.     }
  237.  
  238.     Flush(Output());    
  239.     return res;
  240. }
  241.  
  242. void req(UBYTE *msg) {
  243.     struct EasyStruct easy = {
  244.         sizeof(struct EasyStruct), 0, PROGNAME " error", msg, "OK"
  245.     };
  246.  
  247.     EasyRequest(0, &easy, 0, 0);
  248. }
  249.  
  250. void wbstart(struct WBStartup *msg) {
  251.     struct args args;
  252.     struct DiskObject *dobj;
  253.     BPTR oldCD;
  254.  
  255.     args.error = &req;
  256.  
  257.     if (msg->sm_NumArgs == 1) {
  258.         args.file = 0;
  259.     } else {
  260.         args.file = msg->sm_ArgList[msg->sm_NumArgs - 1].wa_Name;
  261.     }
  262.  
  263.     oldCD = CurrentDir(msg->sm_ArgList[msg->sm_NumArgs - 1].wa_Lock);
  264.     if (dobj = GetDiskObjectNew(msg->sm_ArgList[msg->sm_NumArgs - 1].wa_Name)) {
  265.         args.pubscr = FindToolType(dobj->do_ToolTypes, "PUBSCREEN");
  266.         args.ownscr = FindToolType(dobj->do_ToolTypes, "OWNSCREEN");
  267.         args.port   = FindToolType(dobj->do_ToolTypes, "PORTNAME");
  268.     } else {
  269.         args.pubscr = 0;
  270.         args.ownscr = 0;
  271.         args.port   = 0;
  272.     }
  273.     mymain(&args);
  274.     if (dobj) {
  275.         FreeDiskObject(dobj);
  276.     }
  277.     CurrentDir(oldCD);
  278. }
  279.  
  280. /* END OF AGuide.c */
  281.